import React, { Component } from 'react'
// 时钟 组件
class Clock extends Component {
    constructor(props) {
        super(props)
        this.state = {
            date: new Date()
        }
    }
    componentDidMount() {
        this.timer = setInterval(
            () => this.tick(),
            1000
        );
    }
    componentWillUnmount() {
        clearInterval(this.timer)
    }
    tick() {
        this.setState({
            date: new Date()
        })
    }
    render() {
        return (
            <div style={{ textAlign: 'right' }}>
                {this.state.date.toLocaleString()}
            </div>
        )
    }
}
export default Clock